package org.compiere.model;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;

public class Mhrmstatementline extends X_hrm_statement_line {

	/**
	 * 
	 */
	private static final long serialVersionUID = 124638780586034100L;

	public Mhrmstatementline(Properties ctx) {
		super(ctx);
	}
	
	public Mhrmstatementline(Properties ctx, int hrm_statement_line_ID,
			String trxName) {
		super(ctx, hrm_statement_line_ID, trxName);
	}
	
	public Mhrmstatementline(Properties ctx, ResultSet rs, String trxName) {
		super(ctx, rs, trxName);
	}
	
	@Override
	protected boolean afterSave(boolean newRecord, boolean success) {
		
		if(newRecord){
			Mhrmstatement stat = new Mhrmstatement(getCtx(), gethrm_statement_ID(), get_TrxName());
			stat.sethrm_total(stat.gethrm_total().add(getAmount().setScale(2, BigDecimal.ROUND_HALF_UP)).setScale(2, BigDecimal.ROUND_HALF_UP));
			stat.saveEx();
		}
		
		return true;
	}
	
	/* 
	 */
	@Override
	protected boolean beforeDelete() {
		
		Mhrmstatement stat = new Mhrmstatement(getCtx(), gethrm_statement_ID(), get_TrxName());
		stat.sethrm_total(stat.gethrm_total().add(getAmount().negate()));
		stat.saveEx();
		
		return true;
	}
}
